package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseAttrInfo;
import com.atguigu.gmall.product.entity.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lhh
 * @ClassName BaseAttrInfoController
 * @date 2022 2022/11/29
 */
@Api(tags = "平台属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {

    @Resource
    BaseAttrInfoService baseAttrInfoService;

    @Resource
    BaseAttrValueService baseAttrValueService;

    @ApiOperation(value = "根据分类id获取平台属性")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id){
        List<BaseAttrInfo> list=baseAttrInfoService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(list);
    }

    @ApiOperation("添加/修改平台属性")
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        if(baseAttrInfo.getId()!=null){
            //修改操作
            baseAttrInfoService.updateAttrInfo(baseAttrInfo);
        }else {
            //添加操作
            baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        }
        return Result.ok();
    }

    @ApiOperation(value = "根据id获取平台属性数据")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        List<BaseAttrValue> baseAttrValueList=baseAttrValueService.getAttrValueList(attrId);
        return  Result.ok(baseAttrValueList);
    }
}
